# -*- coding: utf-8 -*-
"""
    Created by huangyi at 2020/7/30.
    Description:
    Changelog: all notable changes to this file will be documented
"""
from ....expression.context import Context
from ....expression.exception.invalid_exception import InvalidException
from ....expression.nonterminal.func.func import Func


class Int(Func):

    def get_name(self) -> str:
        return "int"

    def calc(self, ctx: Context, *param):
        if len(param) != 1:
            raise InvalidException("参数只能有一个")
        data = param[0]
        if not isinstance(data, (str, float)):
            raise InvalidException("参数类型错误:" + type(data))
        return int(data)
